<?php

namespace App\Http\Controllers\Admin;

use App;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Model\FriendshipLink;


class ProjectController extends Controller
{

    public function index(Request $request)
    {
        return view('admin.project.index');
    }

    public function create()
    {
        //标签
        return view('admin.project.add');
    }

    //添加业务
    public function store(Request $request)
    {
        $param = $request->input();
        if (empty($param['id'])) {
            $project = new App\Model\GitProject();
            $project->title=$param['title'];
            $project->sort=$param['sort'];
            $project->type=$param['type'];
            $project->url=$param['url'] ?? '';
            $project->pic=$param['pic'] ?? '';
            $project->save();
            return respone_return(200, '添加成功');
        } else {
            $project = App\Model\GitProject::find($param['id']);
            //修改
            $link = set_attributes($project, $param);
            if ($link->save()) {
                return respone_return(200, '修改成功');
            }
        }
        return respone_return(0, '操作失败');
    }

    //删除
    public function delete(Request $request)
    {
        $ids = $request->input('ids');
        if (App\Model\TimeLine::destroy($ids)) {
            return respone_return(200, '删除成功');
        } else {
            return respone_return(0, '删除失败');
        }
    }
}
